package Offer.offer2016;

public class Test10 
{

	public static void main(String[] args) 
	{
		System.out.println(numberOf1(0x80000000));
		System.out.println(NumberOf1InBinary.numberOf1(0x80000000));
	}
    public static int numberOf1(int n)
    {
    	int count=0;
    	while(n!=0)
    	{
    		count++;
    		n=n&(n-1);
    	}
    	return count;
    }
}

class NumberOf1InBinary{
	/**
	 * �����Ŀ
	 * ��һ������ж�һ�������ǲ���2��������
	 * @param n
	 * @return
	 */
	public static int numberOf1(int n){
		int count = 0;
		while(n != 0){
			count ++;
			n = (n - 1)& n;
		}
		return count;
    }
}
